<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	function index(){
		$user_session = $this->session->userdata('rsh_user');
		if(isset($user_session['user_id'])){
			$this->js->go("/user/zhs_center.html");
			exit;
		}
		if($this->input->post('act') == 'login'){
			$ret = array(
				'msg' => '',
				'sycDz' => '',
				'data' => array(
					'url' => '',
				),
			);
			$last_url = $this->input->post('last_url');
			
			if(!isset($last_url) || empty($last_url)){
						$last_url = "/user/zhs_center.html";
			}
			
			$data = array(
				'username' => $this->input->post('usernm'),
				'password' => $this->input->post('password'),
				'savepwd' => $this->input->post('savepwd'),
			);
			if ($data['username']==""){
				$ret['msg'] = '请输入邮箱/手机号';
				echo json_encode($ret);exit;
			}elseif ($data['password']==""){
				$ret['msg'] = '请输入密码';
				echo json_encode($ret);exit;
			}else{
				$this->load->model('User_model', 'user');
				$tmpRow = $this->user->check_login_errnum($data['username']);
				if($tmpRow && $tmpRow['error_num']>=5){
					$ret['msg'] = '操作失误过多,账户已被锁定,请联系客服解锁或者明日再试';
					echo json_encode($ret);exit;
				}
				//$data['password'] = md5(md5($data['password']));
				$user = $this->user->check_login($data['username'],$data['password']);
				if(isset($user['user_id'])){
					//[fstatus:0关闭 1开通 3注销 4冻结]
					if($user['fstatus']==3){
						$ret['msg'] = '账户已注销';
						echo json_encode($ret);exit;
					}
					elseif($user['fstatus']==4){
						$ret['msg'] = '账户已冻结';
						echo json_encode($ret);exit;
					}
					elseif($user['fstatus']==0){
						$ret['msg'] = '账户已关闭';
						echo json_encode($ret);exit;
					}
					$ip = $this->js->get_ip();
					$now = time();
					$user['login_time'] = $now;
					// 数据加密
					
					
					$this->session->set_userdata('rsh_user',$user);
					if($data['savepwd'] == '1'){
						//user_id,username,phone,email,type_id,fstatus
						$this->load->library('func');
						$cookieArr = array($user['user_id'],$user['username'],$user['phone'],$user['email'],$user['type_id'],$user['fstatus']);
						$cookieStr = implode(',',$cookieArr);
						//加密
						$ck_u_str = $this->func->authcode($cookieStr,'ENCODE','zhsjr_login');
						setcookie("zhsjr_online", $ck_u_str, time()+3600*24*7,'/');
					}
					
					$user = $this->user->get_by_uid($user['user_id']);
					$this->user->update_invest_rank($user['user_id'],$user['invest_score']);
					$setArr = array(
						'logintime' => $user['logintime']+1,
						'uptime' => $user['lasttime'],
						'upip' => $user['lastip'],
						'lasttime' => $now,
						'lastip' => $ip,
						'error_num' => 0,
					);
					$this->user->update($setArr,array('user_id'=>$user['user_id']));
					$ret['data']['url'] = $last_url;
					
					//新增 添加登录日志
					$addLog = array(
						'login_name' => $data['username'],
						'login_state' => 10,
						'login_time' => $now,
						'login_ip' => $ip
					);
					$this->user->add_user_login_log($addLog);					
					echo json_encode($ret);exit;
				}else{
					$this->user->set_error_num($data['username']);
					//新增 添加登录日志
					$addLog = array(
						'login_name' => $data['username'],
						'login_state' => 2,
						'login_time' => time(),
						'login_ip' => $this->js->get_ip()
					);
					$this->user->add_user_login_log($addLog);
					
					$ret['msg'] = '账号或密码错误';
					echo json_encode($ret);exit;
				}
			}
		}else{
			$data['title'] = "用户登录".' - '.CON_KEYWORDS;
			$this->load->view('user/zhs_user_login');
		}
	}

}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
    
	function index(){
		$user_session = $this->session->userdata('rsh_user');
		if(isset($user_session['user_id'])){
			$this->js->go("/user/zhs_center.html");
			exit;
		}
		if($this->input->post('act') == 'login'){
			$ret = array(
				'msg' => '',
				'sycDz' => '',
				'data' => array(
					'url' => '',
				),
			);
			$last_url = $this->input->post('last_url');
			
			if(!isset($last_url) || empty($last_url)){
						$last_url = "/user/zhs_center.html";
			}
			
			$data = array(
				'username' => $this->input->post('usernm'),
				'password' => $this->input->post('password'),
				'savepwd' => $this->input->post('savepwd'),
			);
			if ($data['username']==""){
				$ret['msg'] = '请输入邮箱/手机号';
				echo json_encode($ret);exit;
			}elseif ($data['password']==""){
				$ret['msg'] = '请输入密码';
				echo json_encode($ret);exit;
			}else{
				$this->load->model('User_model', 'user');
				$tmpRow = $this->user->check_login_errnum($data['username']);
				if($tmpRow && $tmpRow['error_num']>=5){
					$ret['msg'] = '操作失误过多,账户已被锁定,请联系客服解锁或者明日再试';
					echo json_encode($ret);exit;
				}
				//$data['password'] = md5(md5($data['password']));
				$user = $this->user->check_login($data['username'],$data['password']);
				if(isset($user['user_id'])){
					//[fstatus:0关闭 1开通 3注销 4冻结]
					if($user['fstatus']==3){
						$ret['msg'] = '账户已注销';
						echo json_encode($ret);exit;
					}
					elseif($user['fstatus']==4){
						$ret['msg'] = '账户已冻结';
						echo json_encode($ret);exit;
					}
					elseif($user['fstatus']==0){
						$ret['msg'] = '账户已关闭';
						echo json_encode($ret);exit;
					}
					$ip = $this->js->get_ip();
					$now = time();
					$user['login_time'] = $now;
					// 数据加密
					
					
					$this->session->set_userdata('rsh_user',$user);
					if($data['savepwd'] == '1'){
						//user_id,username,phone,email,type_id,fstatus
						$this->load->library('func');
						$cookieArr = array($user['user_id'],$user['username'],$user['phone'],$user['email'],$user['type_id'],$user['fstatus']);
						$cookieStr = implode(',',$cookieArr);
						//加密
						$ck_u_str = $this->func->authcode($cookieStr,'ENCODE','zhsjr_login');
						setcookie("zhsjr_online", $ck_u_str, time()+3600*24*7,'/');
					}
					
					$user = $this->user->get_by_uid($user['user_id']);
					$this->user->update_invest_rank($user['user_id'],$user['invest_score']);
					$setArr = array(
						'logintime' => $user['logintime']+1,
						'uptime' => $user['lasttime'],
						'upip' => $user['lastip'],
						'lasttime' => $now,
						'lastip' => $ip,
						'error_num' => 0,
					);
					$this->user->update($setArr,array('user_id'=>$user['user_id']));
					$ret['data']['url'] = $last_url;
					
					//新增 添加登录日志
					$addLog = array(
						'login_name' => $data['username'],
						'login_state' => 10,
						'login_time' => $now,
						'login_ip' => $ip
					);
					$this->user->add_user_login_log($addLog);					
					echo json_encode($ret);exit;
				}else{
					$this->user->set_error_num($data['username']);
					//新增 添加登录日志
					$addLog = array(
						'login_name' => $data['username'],
						'login_state' => 2,
						'login_time' => time(),
						'login_ip' => $this->js->get_ip()
					);
					$this->user->add_user_login_log($addLog);
					
					$ret['msg'] = '账号或密码错误';
					echo json_encode($ret);exit;
				}
			}
		}else{
			$data['title'] = "用户登录".' - '.CON_KEYWORDS;
			$this->load->view('user/zhs_user_login');
		}
	}

}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
